<html>
<head><meta charset="utf-8"><title>mir borrow checker: current scope&#x27;s type arguments? · t-compiler · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/index.html">t-compiler</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/mir.20borrow.20checker.3A.20current.20scope&#x27;s.20type.20arguments.3F.html">mir borrow checker: current scope&#x27;s type arguments?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="154439974"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/mir%20borrow%20checker%3A%20current%20scope%27s%20type%20arguments%3F/near/154439974" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Esteban Küber <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/mir.20borrow.20checker.3A.20current.20scope&#x27;s.20type.20arguments.3F.html#154439974">(Jan 04 2019 at 21:51)</a>:</h4>
<p>Is there a canonical way to get the current scope's type arguments from the <code>MirBorrowckCtxt</code><br>
Context: <a href="https://github.com/rust-lang/rust/pull/57294" target="_blank" title="https://github.com/rust-lang/rust/pull/57294">https://github.com/rust-lang/rust/pull/57294</a><br>
I'd like to get the type argument if the current <code>Ty</code> corresponds to them in order to suggest an appropriate binding restriction.</p>



<a name="154439996"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/mir%20borrow%20checker%3A%20current%20scope%27s%20type%20arguments%3F/near/154439996" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Esteban Küber <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/mir.20borrow.20checker.3A.20current.20scope&#x27;s.20type.20arguments.3F.html#154439996">(Jan 04 2019 at 21:51)</a>:</h4>
<p><span class="user-mention" data-user-id="116009">@nikomatsakis</span> My guess is that you'd be the best person to ask :^)</p>



<a name="154441019"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/mir%20borrow%20checker%3A%20current%20scope%27s%20type%20arguments%3F/near/154441019" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> davidtwco <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/mir.20borrow.20checker.3A.20current.20scope&#x27;s.20type.20arguments.3F.html#154441019">(Jan 04 2019 at 22:05)</a>:</h4>
<p>Not sure if I've done it before, but I'd try calling <a href="https://doc.rust-lang.org/nightly/nightly-rustc/rustc/ty/struct.TyCtxt.html#method.generics_of" target="_blank" title="https://doc.rust-lang.org/nightly/nightly-rustc/rustc/ty/struct.TyCtxt.html#method.generics_of"><code>generics_of</code></a> with <code>self.mir_def_id</code>?</p>



<a name="154441078"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/mir%20borrow%20checker%3A%20current%20scope%27s%20type%20arguments%3F/near/154441078" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> davidtwco <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/mir.20borrow.20checker.3A.20current.20scope&#x27;s.20type.20arguments.3F.html#154441078">(Jan 04 2019 at 22:06)</a>:</h4>
<p>I think that has information about the type parameters.</p>



<a name="154441178"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/mir%20borrow%20checker%3A%20current%20scope%27s%20type%20arguments%3F/near/154441178" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> davidtwco <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/mir.20borrow.20checker.3A.20current.20scope&#x27;s.20type.20arguments.3F.html#154441178">(Jan 04 2019 at 22:08)</a>:</h4>
<p>If you've got a <code>Ty</code> then you could get the relevant generic from that (assuming it is a <code>ty::TyKind::Param</code>) with the <a href="https://doc.rust-lang.org/nightly/nightly-rustc/rustc/ty/struct.Generics.html#method.type_param" target="_blank" title="https://doc.rust-lang.org/nightly/nightly-rustc/rustc/ty/struct.Generics.html#method.type_param"><code>type_param</code></a> function?</p>



<a name="154441369"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/mir%20borrow%20checker%3A%20current%20scope%27s%20type%20arguments%3F/near/154441369" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> davidtwco <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/mir.20borrow.20checker.3A.20current.20scope&#x27;s.20type.20arguments.3F.html#154441369">(Jan 04 2019 at 22:10)</a>:</h4>
<p>Not sure if you'd need to start looking at the predicates on the function so you correctly suggest a <code>T: ... + Copy</code> or just <code>T: Copy</code> depending if the user already specified some constraints.</p>



<a name="154441397"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/mir%20borrow%20checker%3A%20current%20scope%27s%20type%20arguments%3F/near/154441397" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> davidtwco <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/mir.20borrow.20checker.3A.20current.20scope&#x27;s.20type.20arguments.3F.html#154441397">(Jan 04 2019 at 22:10)</a>:</h4>
<p>Just some ideas in case you hadn't looked at those functions already.</p>



<a name="154441580"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/mir%20borrow%20checker%3A%20current%20scope%27s%20type%20arguments%3F/near/154441580" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Esteban Küber <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/mir.20borrow.20checker.3A.20current.20scope&#x27;s.20type.20arguments.3F.html#154441580">(Jan 04 2019 at 22:13)</a>:</h4>
<p>That sounds reasonable and promising. I'll take a look at that this weekend.</p>



<a name="154535631"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/mir%20borrow%20checker%3A%20current%20scope%27s%20type%20arguments%3F/near/154535631" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Esteban Küber <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/mir.20borrow.20checker.3A.20current.20scope&#x27;s.20type.20arguments.3F.html#154535631">(Jan 06 2019 at 23:24)</a>:</h4>
<p><span class="user-mention" data-user-id="116107">@davidtwco</span> <a href="https://github.com/rust-lang/rust/pull/57294/commits/abbf5a2cb7cf1bce8b8ca5f6dc23cd9ccffa8d1c" target="_blank" title="https://github.com/rust-lang/rust/pull/57294/commits/abbf5a2cb7cf1bce8b8ca5f6dc23cd9ccffa8d1c">that worked</a>, thank you! <span class="emoji emoji-1f44d" title="thumbs up">:thumbs_up:</span></p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>